/**
 * 
 */
package sequence.recorder;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

class RecordingGameState extends BasicGameState {
	private Sound sound;

	private int id = 0;

	private long start;

	private TrackList trackList;

	public RecordingGameState(TrackList trackList) throws SlickException {
		this.trackList = trackList;
//		sound = new Sound("res/bed_001ebo.ogg");
		// sound = new Sound("res/Pink Floyd - 06 - One Of Yhese Days.ogg");
		start = System.currentTimeMillis();
	}

	@Override
	public int getID() {
		return 0;
	}

	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
//		sound.play();
	}

	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
	}

	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		long time = 0;
		if (container.getInput().isKeyPressed(Input.KEY_ESCAPE)) {
			container.exit();
		} else {
			time = System.currentTimeMillis() - start;
			for (Track track : trackList) {
				if (container.getInput().isKeyPressed(track.getKey())) {
					track.getSequence().add(time, ++id);
					System.out.printf("%d %d\n", time, id);
				}
			}
		}
	}

}